<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Iniciar Sesion</title>
    </h:head>
    <h:body>
        <h:outputLink id="loginLink" value="javascript:void(0)" onclick="dlg.show()" title="login">
            <p:graphicImage id="centrar" value="/resources/img/comenzar.png" />
        </h:outputLink>

        <p:growl id="growl" showDetail="true" life="3000" />
        <h:form>
            <p:dialog id="dialog" header="Acceso solo para personal autorizado" widgetVar="dlg" modal="true">


                <h:panelGrid columns="2" cellpadding="5">
                    <h:outputLabel for="nombre" value="Usuario:" />
                    <p:inputText value="#{loginBean.usuario.nombre}" id="nombre" required="true" label="nombre" />
                    
                    <h:outputLabel for="contrasenia" value="Constrase&ntilde;a:" />
                    <h:inputSecret value="#{loginBean.usuario.contrasenia}" id="contrasenia" required="true" label="contrasenia" />

                    <f:facet name="footer">
                        <p:commandButton id="loginButton" value="Ingresar" update=":growl" actionListener="#{loginBean.login}" oncomplete="handleLoginRequest(xhr, status, args)"/>
                    </f:facet>
                </h:panelGrid>


            </p:dialog>
        </h:form>

        <script type="text/javascript">
                function handleLoginRequest(xhr, status, args) {
                    if (args.validationFailed || !args.loggedIn) {
                        dlg.jq.effect("shake", {times: 5}, 100);
                    }
                    else {
                        dlg.hide();
                        $('#loginLink').fadeOut();
                        window.location="/WebImbNeciosup/inicio.jsf";
                    }
                }
        </script>  
    </h:body>
</html>

